package com.demo.controller;

import com.demo.domain.Person;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
public class WebController {

    @RequestMapping("/str")
    @ResponseBody
    public String json1(){
        return "字符串";
    }

    @RequestMapping("/obj")
    @ResponseBody
    public Person json2(){
        return new Person(1L,"对象-日期",new Date());
    }

    @RequestMapping("/array")
    @ResponseBody
    public List<Person> json3(){
        return Arrays.asList(new Person(1L,"数组-数据1",new Date()),new Person(2L,"数组-数据2",new Date()));
    }

    @RequestMapping("/index")
    public String jsp(Model model){
        model.addAttribute("msg", "后台传的数据...");
        return "index";
    }

}
